﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Security;

using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

using SPBusiness.ExtensionMethods;
using Microsoft.SharePoint.Taxonomy;

namespace SPBusiness
{
   public sealed class CustomUserProfile
    {
       /// <summary>
       /// CustomUserProfile class has only Static Methods, no constructor needed.
       /// </summary>
       private CustomUserProfile() { }

       public static string[] GetUserProfileProperties(string pSiteUrl, string pAccountName, string[] pPropertiesNames)
        {
            try
            {

                List<string> vReturn = new List<string>();

                using (SPSite vSPSite = new SPSite(pSiteUrl))
                {
                    SPServiceContext vSPServiceContext = SPServiceContext.GetContext(vSPSite);

                    UserProfileManager vUserProfileManager = new UserProfileManager(vSPServiceContext);

                    UserProfile vUserProfile = vUserProfileManager.GetUserProfile(pAccountName);

                    foreach (string vPropertyName in pPropertiesNames)
                    {
                        if (vUserProfile[vPropertyName].Value != null)
                        {
                            vReturn.Add(vUserProfile[vPropertyName].ToString());
                        }
                        else
                        {
                            vReturn.Add(null);
                        }

                    }

                }

                return vReturn.ToArray();

            }
            catch (Exception ex)
            {
                Logging.LogMessase(typeof(CustomUserProfile).Namespace, typeof(CustomUserProfile).Name, "GetUserProfileProperties", ex);
                throw;
            }
        }

    
    }
}
